import '../helper/dioHelper2.dart';

class InspectReport {
  int ID;
  String Guid;
  String Zone;
  String UserId;
  String CreateTM;
  String Members;
  String InspectType;
  String EndTM;
  int State;
  String Content;
  String Problem;
  String Dealwith;
  String GpsRemark;
  double Distance;
  double MinutesLast;
  String Wt1;
  String Wt2;
  String Wt3;
  String Wt4;
  String Wt5;
  String Wt6;
  String Wt7;
  String Wt8;
  String Wt9;
  String Bz1;
  String Bz2;
  String Bz3;

  InspectReport(
      this.ID,
      this.Guid,
      this.Zone,
      this.UserId,
      this.CreateTM,
      this.Members,
      this.InspectType,
      this.EndTM,
      this.State,
      this.Content,
      this.Problem,
      this.Dealwith,
      this.GpsRemark,
      this.Distance,
      this.MinutesLast,
      this.Wt1,
      this.Wt2,
      this.Wt3,
      this.Wt4,
      this.Wt5,
      this.Wt6,
      this.Wt7,
      this.Wt8,
      this.Wt9,
      this.Bz1,
      this.Bz2,
      this.Bz3);
  InspectReport.fromJson(Map<String, dynamic> json)
      : ID = json["ID"],
        Guid = json["Guid"],
        Zone = json["Zone"],
        UserId = json["UserId"],
        CreateTM = json["CreateTM"],
        Members = json["Members"],
        InspectType = json["InspectType"],
        EndTM = json["EndTM"],
        State = json["State"],
        Content = json["Content"],
        Problem = json["Problem"],
        Dealwith = json["Dealwith"],
        GpsRemark = json["GpsRemark"],
        Distance = json["Distance"] * 1.0,
        MinutesLast = json["MinutesLast"] * 1.0,
        Wt1 = json["Wt1"],
        Wt2 = json["Wt2"],
        Wt3 = json["Wt3"],
        Wt4 = json["Wt4"],
        Wt5 = json["Wt5"],
        Wt6 = json["Wt6"],
        Wt7 = json["Wt7"],
        Wt8 = json["Wt8"],
        Wt9 = json["Wt9"],
        Bz1 = json["Bz1"],
        Bz2 = json["Bz2"],
        Bz3 = json["Bz3"];
  Map<String, dynamic> toJson() => {
        'ID': ID,
        'Guid': Guid,
        'Zone': Zone,
        'UserId': UserId,
        'CreateTM': CreateTM,
        'Members': Members,
        'InspectType': InspectType,
        'EndTM': EndTM,
        'State': State,
        'Content': Content,
        'Problem': Problem,
        'Dealwith': Dealwith,
        'GpsRemark': GpsRemark,
        'Distance': Distance,
        'MinutesLast': MinutesLast,
        'Wt1': Wt1,
        'Wt2': Wt2,
        'Wt3': Wt3,
        'Wt4': Wt4,
        'Wt5': Wt5,
        'Wt6': Wt6,
        'Wt7': Wt7,
        'Wt8': Wt8,
        'Wt9': Wt9,
        'Bz1': Bz1,
        'Bz2': Bz2,
        'Bz3': Bz3,
      };

  static Future<bool> Add(InspectReport x1) async {
    print(x1.toJson());
    var response = await DioHelper.Post("/InspectReport/Add", x1.toJson());
    if (response.statusCode == 200) return true;
    return false;
  }

  static Future<bool> Update(InspectReport x1) async {
    var response = await DioHelper.Post("/InspectReport/Update", x1.toJson());
    if (response.statusCode == 200) return true;
    return false;
  }

  static Future<bool> Delete(InspectReport x1) async {
    var st = x1.toJson();
    var response = await DioHelper.Post("/InspectReport/Delete", x1.toJson());
    if (response.statusCode == 200) return true;
    return false;
  }

  static Future<InspectReport?> Get(String where, dynamic data) async {
    var response = await DioHelper.Post("/InspectReport/GetByWhere", {
      "Where": where,
      "obj": data,
    });

    if (response.statusCode == 200)
      return new InspectReport.fromJson(response.data);
    return null;
  }

  static Future<List<InspectReport>> GetList(
      int pageIndex, int pageSize) async {
    var response = await DioHelper.Get(
        "/InspectReport/GetList?st=0&p1=" +
            pageIndex.toString() +
            "&ps=" +
            pageSize.toString(),
        {});

    var list1 = <InspectReport>[];
    if (response.statusCode == 200) {
      //print(response.data);
      if (response.data == null) return list1;
      for (var x in response.data) {
        list1.add(new InspectReport.fromJson(x));
      }
    }
    return list1;
  }

  static Future<List<InspectReport>> GetAllList() async {
    var response = await DioHelper.Get("/InspectReport/GetAllList", {});
    var list1 = <InspectReport>[];
    if (response.statusCode == 200) {
      for (var x in response.data) {
        list1.add(new InspectReport.fromJson(x));
      }
    }
    return list1;
  }
}
